#include "level.h"
#include "levelactor.h"
#include "levelobjectselectionmanager.h"

using namespace LevelObjects;

Level::Level( QObject *parent, const QString& name )
	: AbstractLevelObject(parent, name)
	, m_selectionManager(new LevelObjectSelectionManager(this))
{

}

LevelObjects::LevelObjectType LevelObjects::Level::type() const
{
	return LOT_Level;
}

QPointer<LevelObjects::AbstractLevelObject> LevelObjects::Level::createLevelObject( const QString& name, QPointer<AbstractGameObject> go ,
	QPointer<AbstractLevelObject> parentLevelActor /*= QPointer<AbstractLevelObject>()*/ )
{
	QString levelObjectName = name;
	if(levelObjectName == "")
	{
		levelObjectName = QString("Actor%1").arg(m_levelActors.size());
	}

	QPointer<LevelObjects::AbstractLevelObject> result = new LevelActor(this, go, levelObjectName);
	add(result);
	return result;
}

void LevelObjects::Level::add( QPointer<AbstractLevelObject> lo )
{
	m_levelActors << lo;
	emit levelObjectAdded(lo);
}

void LevelObjects::Level::remove( QPointer<AbstractLevelObject> lo )
{
	m_levelActors.removeOne(lo);
	emit levelObjectRemoved(lo);
}

const LevelObjects::Level::LevelActors& LevelObjects::Level::levelActors() const
{
	return m_levelActors;
}

QPointer<LevelObjectSelectionManager> LevelObjects::Level::selectionManager() const
{
	return m_selectionManager;
}
